<template>
	<cl-crud ref="Crud">
		<cl-row>
			<!-- 刷新按钮 -->
			<cl-refresh-btn />
			<!-- 新增按钮 -->
			<!-- <cl-add-btn /> -->
			<!-- 删除按钮 -->
			<!-- <cl-multi-delete-btn /> -->
			<cl-flex1 />
			<!-- 条件搜索 -->
			<cl-search ref="Search" />
		</cl-row>

		<cl-row>
			<!-- 数据表格 -->
			<cl-table ref="Table" />
		</cl-row>

		<cl-row>
			<cl-flex1 />
			<!-- 分页控件 -->
			<cl-pagination />
		</cl-row>

		<!-- 新增、编辑 -->
		<cl-upsert ref="Upsert" />
	</cl-crud>
</template>

<script lang="ts" setup>
defineOptions({
	name: 'finance-profit'
});

import { useCrud, useTable, useUpsert, useSearch } from '@cool-vue/crud';
import { useCool } from '/@/cool';
import { useI18n } from 'vue-i18n';
import { reactive } from 'vue';

const { service } = useCool();
const { t } = useI18n();

// 选项
const options = reactive({
	profitStatus: [
		{ label: t('待结算'), value: 0, type: 'danger' },
		{ label: t('已结算'), value: 1, type: 'success' }
	]
});

// cl-table
const Table = useTable({
	columns: [
		{ type: 'selection' },
		// {
		// 	label: t('分润状态'),
		// 	prop: 'profitStatus',
		// 	minWidth: 120,
		// 	dict: options.profitStatus
		// },
		// {
		// 	label: t('分润时间'),
		// 	prop: 'profitTime',
		// 	minWidth: 170,
		// 	sortable: 'custom',
		// 	component: { name: 'cl-date-text' }
		// },
		{ label: t('关联订单ID'), prop: 'orderId', minWidth: 120 },
		{
			label: t('订单金额'),
			prop: 'totalAmount',
			minWidth: 120,
			render: row => `￥${row.totalAmount / 100}`
		},
		{ label: t('平台扣点'), prop: 'platformDeduction', minWidth: 120 },
		{ label: t('商家到账'), prop: 'sellerAmount', minWidth: 120, render: row => `￥${row.sellerAmount / 100}` },
		{
			label: t('一级代理分润'),
			prop: 'level1Amount',
			minWidth: 120,
			render: row => `￥${row.level1Amount / 100}`
		},
		{
			label: t('二级代理分润'),
			prop: 'level2Amount',
			minWidth: 120,
			render: row => `￥${row.level2Amount / 100}`
		},
		{
			label: t('三级代理分润'),
			prop: 'level3Amount',
			minWidth: 120,
			render: row => `￥${row.level3Amount / 100}`
		},
		{
			label: t('费率'),
			prop: 'platformRatio',
			minWidth: 120,
			render: row => `￥${(row.platformRatio / 100).toFixed(2)}`
		},
		{
			label: t('创建时间'),
			prop: 'createTime',
			minWidth: 170,
			sortable: 'desc',
			component: { name: 'cl-date-text' }
		}, 
		// { type: 'op', buttons: ['edit', 'delete'] }
	]
});

// cl-search
const Search = useSearch();

// cl-crud
const Crud = useCrud(
	{
		service: service.finance.profit
	},
	app => {
		app.refresh();
	}
);

// 刷新
function refresh(params?: any) {
	Crud.value?.refresh(params);
}
</script>
